Grokking Dynamic Programming Patterns for Coding Interviews
Rate this course
Ask Author
Contribute
Back to course home

0% completed

Vote For New Content
Introduction
What is Dynamic Programming?
Pattern 1: 0/1 Knapsack
Introduction
0/1 Knapsack
Solution: 0/1 Knapsack
Equal Subset Sum Partition
Solution: Equal Subset Sum Partition
Subset Sum
Solution: Subset Sum
Minimum Subset Sum Difference
Solution: Minimum Subset Sum Difference
Count of Subset Sum
Solution: Count of Subset Sum
Target Sum
Solution: Target Sum
Pattern 2: Unbounded Knapsack
Unbounded Knapsack
Solution: Unbounded Knapsack
Rod Cutting
Solution: Rod Cutting
Coin Change
Solution: Coin Change
Minimum Coin Change
Solution: Minimum Coin Change
Maximum Ribbon Cut
Solution: Maximum Ribbon Cut
Pattern 3: Fibonacci Numbers
Fibonacci numbers
Solution: Fibonacci numbers
Staircase
Solution: Staircase
Number factors
Solution: Number factors
Minimum jumps to reach the end
Solution: Minimum jumps to reach the end
Minimum jumps with fee
Solution: Minimum jumps with fee
House thief
Solution: House thief
Pattern 4: Palindromic Subsequence
Longest Palindromic Subsequence
Solution: Longest Palindromic Subsequence
Longest Palindromic Substring
Solution: Longest Palindromic Substring
Count of Palindromic Substrings
Solution: Count of Palindromic Substrings
Minimum Deletions in a String to make it a Palindrome
Solution: Minimum Deletions in a String to make it a Palindrome
Palindromic Partitioning
Solution: Palindromic Partitioning
Pattern 5: Longest Common Substring
Longest Common Substring
Solution: Longest Common Substring
Longest Common Subsequence
Solution: Longest Common Subsequence
Minimum Deletions & Insertions to Transform a String into another
Solution: Minimum Deletions & Insertions to Transform a String into another
Longest Increasing Subsequence
Solution: Longest Increasing Subsequence
Maximum Sum Increasing Subsequence
Solution: Maximum Sum Increasing Subsequence
Shortest Common Super-sequence
Solution: Shortest Common Super-sequence
Minimum Deletions to Make a Sequence Sorted
Solution: Minimum Deletions to Make a Sequence Sorted
Longest Repeating Subsequence
Solution: Longest Repeating Subsequence
Subsequence Pattern Matching
Solution: Subsequence Pattern Matching
Longest Bitonic Subsequence
Solution: Longest Bitonic Subsequence
Longest Alternating Subsequence
Solution: Longest Alternating Subsequence
Edit Distance
Solution: Edit Distance
Strings Interleaving
Solution: Strings Interleaving
Contact Us
Longest Repeating Subsequence

Problem Statement

Given a sequence, find the length of its longest repeating subsequence (LRS). A repeating subsequence will be the one that appears at least twice in the original sequence and is not overlapping (i.e. none of the corresponding characters in the repeating subsequences have the same index).

Example 1:

Input: "t o m o r r o w"
Output: 2
Explanation: The longest repeating subsequence is "or" {tomorrow}.

Example 2:

Input: "a a b d b c e c"
Output: 3
Explanation: The longest repeating subsequence is "a b c" {a a b d b c e c}.

Example 3:

Input: "f m f f"
Output: 2
Explanation: The longest repeating subsequence is "f f" {f m f f, f m f f}. Please note the second last character is shared in LRS.

Try it yourself

Try solving this question here:

Java
Saved to Cloud

. . . .
Solution: Minimum Deletions to Make a Sequence Sorted
Solution: Longest Repeating Subsequence
Mark as Completed

On this page

Problem Statement

Try it yourself